package androidx.appcompat.widget;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.MeasureSpec;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.ViewGroup.MarginLayoutParams;
import android.view.accessibility.AccessibilityEvent;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.RestrictTo;
import androidx.annotation.RestrictTo.d;
import androidx.core.view.ViewCompat;
import o.ah$i;
import o.ah$j;
import o.ah.c;
import o.ah.g;
import o.aw;
import o.bd;
import o.bu;
import o.cw;
import o.de;
import o.ic;

@RestrictTo({d.LIBRARY_GROUP})
public class ActionBarContextView extends bu {
    private CharSequence ʻ;
    private View ʽ;
    private TextView ˊॱ;
    private int ˋॱ;
    private LinearLayout ˏॱ;
    private TextView ͺ;
    private int ॱˊ;
    private int ॱˋ;
    private boolean ॱˎ;
    private View ॱॱ;
    private CharSequence ᐝ;

    public /* bridge */ /* synthetic */ boolean onHoverEvent(MotionEvent motionEvent) {
        return super.onHoverEvent(motionEvent);
    }

    public /* bridge */ /* synthetic */ boolean onTouchEvent(MotionEvent motionEvent) {
        return super.onTouchEvent(motionEvent);
    }

    public /* bridge */ /* synthetic */ void setVisibility(int i) {
        super.setVisibility(i);
    }

    public /* bridge */ /* synthetic */ ic ˊ(int i, long j) {
        return super.ˊ(i, j);
    }

    public ActionBarContextView(Context context) {
        this(context, null);
    }

    public ActionBarContextView(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, c.ˊॱ);
    }

    public ActionBarContextView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        cw ॱ = cw.ॱ(context, attributeSet, g.ʽॱ, i, 0);
        ViewCompat.ˏ(this, ॱ.ˋ(g.ˊˊ));
        this.ˋॱ = ॱ.ॱॱ(g.ˋˊ, 0);
        this.ॱˊ = ॱ.ॱॱ(g.ˉ, 0);
        this.ॱ = ॱ.ʼ(g.ˊᐝ, 0);
        this.ॱˋ = ॱ.ॱॱ(g.ˊˋ, ah$j.ˊ);
        ॱ.ॱ();
    }

    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        if (this.ˊ != null) {
            this.ˊ.ˊ();
            this.ˊ.ॱॱ();
        }
    }

    public void setContentHeight(int i) {
        this.ॱ = i;
    }

    public void setCustomView(View view) {
        if (this.ॱॱ != null) {
            removeView(this.ॱॱ);
        }
        this.ॱॱ = view;
        if (!(view == null || this.ˏॱ == null)) {
            removeView(this.ˏॱ);
            this.ˏॱ = null;
        }
        if (view != null) {
            addView(view);
        }
        requestLayout();
    }

    public void setTitle(CharSequence charSequence) {
        this.ᐝ = charSequence;
        ʼ();
    }

    public void setSubtitle(CharSequence charSequence) {
        this.ʻ = charSequence;
        ʼ();
    }

    public CharSequence ˋ() {
        return this.ᐝ;
    }

    public CharSequence ॱ() {
        return this.ʻ;
    }

    private void ʼ() {
        int i;
        int i2 = 8;
        Object obj = 1;
        if (this.ˏॱ == null) {
            LayoutInflater.from(getContext()).inflate(ah$j.ˋ, this);
            this.ˏॱ = (LinearLayout) getChildAt(getChildCount() - 1);
            this.ͺ = (TextView) this.ˏॱ.findViewById(ah$i.ˏ);
            this.ˊॱ = (TextView) this.ˏॱ.findViewById(ah$i.ˎ);
            if (this.ˋॱ != 0) {
                this.ͺ.setTextAppearance(getContext(), this.ˋॱ);
            }
            if (this.ॱˊ != 0) {
                this.ˊॱ.setTextAppearance(getContext(), this.ॱˊ);
            }
        }
        this.ͺ.setText(this.ᐝ);
        this.ˊॱ.setText(this.ʻ);
        Object obj2 = !TextUtils.isEmpty(this.ᐝ) ? 1 : null;
        if (TextUtils.isEmpty(this.ʻ)) {
            obj = null;
        }
        TextView textView = this.ˊॱ;
        if (obj != null) {
            i = 0;
        } else {
            i = 8;
        }
        textView.setVisibility(i);
        LinearLayout linearLayout = this.ˏॱ;
        if (!(obj2 == null && obj == null)) {
            i2 = 0;
        }
        linearLayout.setVisibility(i2);
        if (this.ˏॱ.getParent() == null) {
            addView(this.ˏॱ);
        }
    }

    public void ˊ(final aw awVar) {
        if (this.ʽ == null) {
            this.ʽ = LayoutInflater.from(getContext()).inflate(this.ॱˋ, this, false);
            addView(this.ʽ);
        } else if (this.ʽ.getParent() == null) {
            addView(this.ʽ);
        }
        this.ʽ.findViewById(ah$i.ʻ).setOnClickListener(new OnClickListener(this) {
            final /* synthetic */ ActionBarContextView ˋ;

            public void onClick(View view) {
                awVar.ॱ();
            }
        });
        bd bdVar = (bd) awVar.ˏ();
        if (this.ˊ != null) {
            this.ˊ.ʻ();
        }
        this.ˊ = new ActionMenuPresenter(getContext());
        this.ˊ.ˏ(true);
        LayoutParams layoutParams = new LayoutParams(-2, -1);
        bdVar.ˏ(this.ˊ, this.ˋ);
        this.ˏ = (ActionMenuView) this.ˊ.ˏ((ViewGroup) this);
        ViewCompat.ˏ(this.ˏ, null);
        addView(this.ˏ, layoutParams);
    }

    public void ˏ() {
        if (this.ʽ == null) {
            ˊ();
        }
    }

    public void ˊ() {
        removeAllViews();
        this.ॱॱ = null;
        this.ˏ = null;
    }

    public boolean ˎ() {
        if (this.ˊ != null) {
            return this.ˊ.ˎ();
        }
        return false;
    }

    protected LayoutParams generateDefaultLayoutParams() {
        return new MarginLayoutParams(-1, -2);
    }

    public LayoutParams generateLayoutParams(AttributeSet attributeSet) {
        return new MarginLayoutParams(getContext(), attributeSet);
    }

    protected void onMeasure(int i, int i2) {
        int i3 = 1073741824;
        int i4 = 0;
        if (MeasureSpec.getMode(i) != 1073741824) {
            throw new IllegalStateException(getClass().getSimpleName() + " can only be used " + "with android:layout_width=\"match_parent\" (or fill_parent)");
        } else if (MeasureSpec.getMode(i2) == 0) {
            throw new IllegalStateException(getClass().getSimpleName() + " can only be used " + "with android:layout_height=\"wrap_content\"");
        } else {
            int i5;
            int ˏ;
            int size = MeasureSpec.getSize(i);
            if (this.ॱ > 0) {
                i5 = this.ॱ;
            } else {
                i5 = MeasureSpec.getSize(i2);
            }
            int paddingTop = getPaddingTop() + getPaddingBottom();
            int paddingLeft = (size - getPaddingLeft()) - getPaddingRight();
            int i6 = i5 - paddingTop;
            int makeMeasureSpec = MeasureSpec.makeMeasureSpec(i6, Integer.MIN_VALUE);
            if (this.ʽ != null) {
                ˏ = ˏ(this.ʽ, paddingLeft, makeMeasureSpec, 0);
                MarginLayoutParams marginLayoutParams = (MarginLayoutParams) this.ʽ.getLayoutParams();
                paddingLeft = ˏ - (marginLayoutParams.rightMargin + marginLayoutParams.leftMargin);
            }
            if (this.ˏ != null && this.ˏ.getParent() == this) {
                paddingLeft = ˏ(this.ˏ, paddingLeft, makeMeasureSpec, 0);
            }
            if (this.ˏॱ != null && this.ॱॱ == null) {
                if (this.ॱˎ) {
                    this.ˏॱ.measure(MeasureSpec.makeMeasureSpec(0, 0), makeMeasureSpec);
                    ˏ = this.ˏॱ.getMeasuredWidth();
                    makeMeasureSpec = ˏ <= paddingLeft ? 1 : 0;
                    if (makeMeasureSpec != 0) {
                        paddingLeft -= ˏ;
                    }
                    this.ˏॱ.setVisibility(makeMeasureSpec != 0 ? 0 : 8);
                } else {
                    paddingLeft = ˏ(this.ˏॱ, paddingLeft, makeMeasureSpec, 0);
                }
            }
            if (this.ॱॱ != null) {
                int min;
                LayoutParams layoutParams = this.ॱॱ.getLayoutParams();
                if (layoutParams.width != -2) {
                    makeMeasureSpec = 1073741824;
                } else {
                    makeMeasureSpec = Integer.MIN_VALUE;
                }
                if (layoutParams.width >= 0) {
                    paddingLeft = Math.min(layoutParams.width, paddingLeft);
                }
                if (layoutParams.height == -2) {
                    i3 = Integer.MIN_VALUE;
                }
                if (layoutParams.height >= 0) {
                    min = Math.min(layoutParams.height, i6);
                } else {
                    min = i6;
                }
                this.ॱॱ.measure(MeasureSpec.makeMeasureSpec(paddingLeft, makeMeasureSpec), MeasureSpec.makeMeasureSpec(min, i3));
            }
            if (this.ॱ <= 0) {
                makeMeasureSpec = getChildCount();
                i5 = 0;
                while (i4 < makeMeasureSpec) {
                    paddingLeft = getChildAt(i4).getMeasuredHeight() + paddingTop;
                    if (paddingLeft <= i5) {
                        paddingLeft = i5;
                    }
                    i4++;
                    i5 = paddingLeft;
                }
                setMeasuredDimension(size, i5);
                return;
            }
            setMeasuredDimension(size, i5);
        }
    }

    protected void onLayout(boolean z, int i, int i2, int i3, int i4) {
        int i5;
        boolean ˎ = de.ˎ(this);
        int paddingRight = ˎ ? (i3 - i) - getPaddingRight() : getPaddingLeft();
        int paddingTop = getPaddingTop();
        int paddingTop2 = ((i4 - i2) - getPaddingTop()) - getPaddingBottom();
        if (this.ʽ == null || this.ʽ.getVisibility() == 8) {
            i5 = paddingRight;
        } else {
            MarginLayoutParams marginLayoutParams = (MarginLayoutParams) this.ʽ.getLayoutParams();
            i5 = ˎ ? marginLayoutParams.rightMargin : marginLayoutParams.leftMargin;
            int i6 = ˎ ? marginLayoutParams.leftMargin : marginLayoutParams.rightMargin;
            i5 = bu.ˋ(paddingRight, i5, ˎ);
            i5 = bu.ˋ(ॱ(this.ʽ, i5, paddingTop, paddingTop2, ˎ) + i5, i6, ˎ);
        }
        if (!(this.ˏॱ == null || this.ॱॱ != null || this.ˏॱ.getVisibility() == 8)) {
            i5 += ॱ(this.ˏॱ, i5, paddingTop, paddingTop2, ˎ);
        }
        if (this.ॱॱ != null) {
            int ॱ = ॱ(this.ॱॱ, i5, paddingTop, paddingTop2, ˎ) + i5;
        }
        i5 = ˎ ? getPaddingLeft() : (i3 - i) - getPaddingRight();
        if (this.ˏ != null) {
            ॱ = ॱ(this.ˏ, i5, paddingTop, paddingTop2, !ˎ) + i5;
        }
    }

    public boolean shouldDelayChildPressedState() {
        return false;
    }

    public void onInitializeAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
        if (accessibilityEvent.getEventType() == 32) {
            accessibilityEvent.setSource(this);
            accessibilityEvent.setClassName(getClass().getName());
            accessibilityEvent.setPackageName(getContext().getPackageName());
            accessibilityEvent.setContentDescription(this.ᐝ);
            return;
        }
        super.onInitializeAccessibilityEvent(accessibilityEvent);
    }

    public void setTitleOptional(boolean z) {
        if (z != this.ॱˎ) {
            requestLayout();
        }
        this.ॱˎ = z;
    }

    public boolean ʻ() {
        return this.ॱˎ;
    }
}
